package com.gec.yhzh.controller;


import cn.hutool.core.bean.BeanUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gec.yhzh.entity.Doctor;
import com.gec.yhzh.entity.Registration;
import com.gec.yhzh.entity.User;
import com.gec.yhzh.entity.UserDTO;
import com.gec.yhzh.entity.Vo.RegistrationVO;
import com.gec.yhzh.service.IDoctorService;
import com.gec.yhzh.service.IRegistrationService;
import com.gec.yhzh.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 挂号帖 前端控制器
 * </p>
 *
 * @author jerry
 * @since 2025-03-10
 */
@RestController
@RequestMapping("/registration")
public class RegistrationController {
    @Autowired
    IRegistrationService iRegistrationService;
    @Autowired
    IUserService iUserService;
    @Autowired
    IDoctorService iDoctorService;

    //JSON解析工具
    ObjectMapper objectMapper = new ObjectMapper();
@PostMapping(value = "/add", consumes = "application/x-www-form-urlencoded")
    public String add(@ModelAttribute Registration registration ) throws JsonProcessingException {
    Map<String, Object> result = new HashMap<>();
    boolean flag = iRegistrationService.save(registration);

    if (flag)
    {result.put("flag", flag);
    result.put("message", "预约成功");}
    else
    {result.put("flag", flag);
    result.put("message", "预约失败");
    }
    return objectMapper.writeValueAsString(result);
}
}
